/*
题目链接:https://leetcode.cn/problems/minimum-operations-to-make-array-values-equal-to-k/submissions/620592512/?envType=daily-question&envId=2025-04-09
*/

//题解代码:
class Solution {
public:
    int minOperations(vector<int>& nums, int k) {
        int n = nums.size();
        sort(nums.begin(),nums.end());
        if(k>nums[0]) return -1;
        int ans = 0;
        for(int i=n-2;i>=0;--i){
            if(nums[i] != nums[i+1]) ++ans;
        }
        ans += nums[0]!=k;
        return ans;
    }
};
